#include "board.h"
#include "light/ws2812b.h"
#include "rgb_mode/rgb_mode.h"

/* 应该是定义在 BOARD 文件中 */
#define WS2812B_RGB_CNT       16
#define WS2812B_FRAME_MAX_CNT 64

static uint32_t frame[WS2812B_FRAME_MAX_CNT][WS2812B_RGB_CNT];

int main_test(void)
{
	int i = 0;
	int t = 50;
	int frm_cnt = 0;
	rgb_anim_t anim;
	ws2812b_t led;
	uint32_t color = 0x100000; /* 低亮度的红色 */

	led.cfg.fix.num = WS2812B_RGB_CNT;
	led.ops.spi_write = board_spi_write;

	board_init();

	while (1) {
		frm_cnt = rgb_water_frame_count_get(WS2812B_RGB_CNT);
		for (i = 0; i < frm_cnt; i++) {
			anim.led_cnt = WS2812B_RGB_CNT;
			anim.color = color;
			anim.frm_num = i;
			rgb_water_frame_get(&anim, frame[i]);
			ws2812b_write(&led, frame[i], WS2812B_RGB_CNT);
			delay_ms(t);
		}

		frm_cnt = rgb_water_opposite_frame_count_get(WS2812B_RGB_CNT);
		for (i = 0; i < frm_cnt; i++) {
			anim.led_cnt = WS2812B_RGB_CNT;
			anim.color = color;
			anim.frm_num = i;
			rgb_water_opposite_frame_get(&anim, frame[i]);
			ws2812b_write(&led, frame[i], WS2812B_RGB_CNT);
			delay_ms(t);
		}

		frm_cnt = rgb_sequentially_frame_count_get(WS2812B_RGB_CNT);
		for (i = 0; i < frm_cnt; i++) {
			anim.led_cnt = WS2812B_RGB_CNT;
			anim.color = color;
			anim.frm_num = i;
			rgb_sequentially_frame_get(&anim, frame[i]);
			ws2812b_write(&led, frame[i], WS2812B_RGB_CNT);
			delay_ms(t);
		}

		frm_cnt = rgb_sequentially_opposite_frame_count_get(WS2812B_RGB_CNT);
		for (i = 0; i < frm_cnt; i++) {
			anim.led_cnt = WS2812B_RGB_CNT;
			anim.color = color;
			anim.frm_num = i;
			rgb_sequentially_opposite_frame_get(&anim, frame[i]);
			ws2812b_write(&led, frame[i], WS2812B_RGB_CNT);
			delay_ms(t);
		}
	}
}
